#!/usr/bin/python
import os
import sys
from dcinstall import setup_py, debian, AbstractPackageInfo
from dcinstall.version import get_revisions, get_changelog_core, save_last_revision

class build(AbstractPackageInfo.build):
    sources_dir = os.path.realpath(os.path.dirname(__file__))
    build_dir = sources_dir
    result_dir = sources_dir + '/dist'

last_revision, cur_revision = get_revisions(build)

class info(AbstractPackageInfo):
    build = build
    version = '1.30-SVN%d' % cur_revision
    changelog_core = get_changelog_core(last_revision, cur_revision)
    name = 'djwheel'
    maintainer = 'Maxim Oransky'
    maintainer_email = 'maxim.oransky@gmail.com'
    description = 'Set of non-innovation django applications and utilites'
    url = 'http://code.google.com/p/the-wheel-django-apps/'
    deb_depends = [
        'python-imaging (>= 1.1.5-11)',
    ]
    license = 'GNU Lesser General Public License'


###################
# 1. Classic setup.py installer

setup_py.create(info, skipfiles = '.*\.pyc|.*\.pyo|\.svn')


if sys.platform == 'win32':
    os.system('python setup.py sdist --formats=zip')
    setup_py.clean()
else:
    os.system('python setup.py sdist --formats=zip,gztar')
    setup_py.clean()

    ###################
    # 2. Debian package
    debian.build_package(
        info,
        src_files = ['dist/%s-%s.tar.gz' % (info.name, info.version)],
    #    root_dir = build_dir,
        custom_deb_templates = {
            'postinst': '%PRESETS%/simple_python_package_postinst.template',
        }
    )

    os.system('mv %s*deb dist' % info.name)
    os.system('rm -f %s*changes' % info.name)

# on sucess save mark current revision as "last builded"
save_last_revision(build, cur_revision)
